package com.arrogames.blondbattle.music 
{
	import com.arrogames.blondbattle.assets.AssetManager;
	import flash.events.EventDispatcher;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.media.SoundTransform;
	import org.as3commons.logging.api.getLogger;
	import org.as3commons.logging.api.ILogger;
	/**
	 * ...
	 * @author Robin van den Bogaard
	 */
	public class MusicManager extends EventDispatcher {
		
		private static const logger:ILogger = getLogger(MusicManager);
		
		private var menuMusic:BBAudio;
		private var gameMusic:BBAudio;
		
		private static const NOTHING:int = 0;
		private static const GAME:int = 1;
		private static const MENU:int = 2;
		
		private var currentlyPlaying:int;
		private var currentAudio:BBAudio;
		
		private var muted:Boolean;
		
		public function MusicManager() {
			menuMusic = new BBAudio(AssetManager.instance.getSound("MenuMusic"), true, true);
			gameMusic = new BBAudio(AssetManager.instance.getSound("GameMusic"), true, true);
			
			
			currentlyPlaying = NOTHING;
			muted = true;
			if (muted) {
				menuMusic.mute();
				gameMusic.mute();
			}
		}
		
		public function isPlayingGameMusic():Boolean {
			return currentlyPlaying === GAME;
		}
		
		public function changeToGameMusic():void {
			if (currentlyPlaying !== NOTHING) {
				currentAudio.stop();
			}
			currentAudio = gameMusic.play();
			currentlyPlaying = GAME;
			logger.debug("Changed to game music");
		}
		
		public function isPlayingMenuMusic():Boolean {
			return currentlyPlaying === MENU;
		}
		
		public function changeToMenuMusic():void {
			if (currentlyPlaying !== NOTHING) {
				currentAudio.stop();
			}
			currentAudio = menuMusic.play();
			currentlyPlaying = MENU;
			logger.debug("Changed to menu music");
		}
		
		public function isMuted():Boolean {
			return muted;
		}
		
		public function mute():void {
			menuMusic.mute();
			gameMusic.mute();
			muted = true;
			logger.debug("Muted the music");
		}
		
		public function unmute():void {
			menuMusic.unmute();
			gameMusic.unmute();
			muted = false;
			logger.debug("Unmuted the music");
		}
		
	}

}